package org.dxy.infrastructure.persistent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dxy.infrastructure.entity.WorkshopEntity;
import org.dxy.infrastructure.persistent.mapper.WorkshopMapper;
import org.dxy.infrastructure.persistent.service.WorkshopPersistentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 车间持久化服务实现
 */
@Service
public class WorkshopPersistentServiceImpl extends ServiceImpl<WorkshopMapper, WorkshopEntity> implements WorkshopPersistentService {
    
    @Override
    public boolean existsByWorkshopCode(String workshopCode) {
        LambdaQueryWrapper<WorkshopEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkshopEntity::getWorkshopCode, workshopCode);
        return this.count(queryWrapper) > 0;
    }
    
    @Override
    public List<WorkshopEntity> getByFactoryId(Long factoryId) {
        LambdaQueryWrapper<WorkshopEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkshopEntity::getFactoryId, factoryId);
        queryWrapper.orderByDesc(WorkshopEntity::getCreatedTime);
        return this.list(queryWrapper);
    }
}